{% if table.foreignKeys.length > 0 -%}
{# new foreignKeys #}
  -- Update table foreign keys '{{ table.name }}'
{% for foreignKey in table.foreignKeys %}
  if funcAppForeignKeyExists('{{ table.name }}', '{{ foreignKey.columns }}', '{{ foreignKey.refTable }}', '{{ foreignKey.refColumns }}') = 0 then
    insert into temp_app_upgrade_log(message) values ('create table foreingn key: {{ table.name }}:{{ foreignKey.columns }}');
    ALTER TABLE {{ table.name }} ADD CONSTRAINT `{{ foreignKey.name }}` FOREIGN KEY ({{ foreignKey.columns }}) REFERENCES {{ foreignKey.refTable }}({{ foreignKey.refColumns }});
  end if;
{% endfor %}
{%- endif -%}